//
//  BackgroundObject.m
//  CandyJump
//
//  Created by Bon Lam on 05/04/2011.
//  Copyright 2011 Peru Republic. All rights reserved.
//

#import "BackgroundObject.h"
#import "BackgroundObject+ProtectedMethods.h"

#import "CCSprite.h"

//=====================================================================================================================
@implementation BackgroundObject

@synthesize name;
@synthesize posx;
@synthesize posy;
@synthesize posz;
@synthesize repeat;
@synthesize repeatOffset;
@synthesize scrollOffset;
@synthesize scrollX;
@synthesize scrollY;

#pragma mark -
#pragma mark Object Functions
//---------------------------------------------------------------------------------------------------------------------
- (id)init
{
	self = [super init];
	if (self == nil)  {return self;}

	scrollX = 1.0f;
	scrollY = 1.0f;
	
	return self;
}

//---------------------------------------------------------------------------------------------------------------------
- (void)dealloc
{
	[name release];
	[super dealloc];
}

//---------------------------------------------------------------------------------------------------------------------
- (id)copyWithZone:(NSZone *)zone
{
	BackgroundObject *backgroundObject = [super copyWithZone:zone];
	backgroundObject->name = [name retain];
	backgroundObject->posx = posx;
	backgroundObject->posy = posy;
	backgroundObject->scrollX = scrollX;
	backgroundObject->scrollY = scrollY;
	backgroundObject->scrollOffset = scrollOffset;
	backgroundObject->repeat = repeat;
	backgroundObject->repeatOffset = repeatOffset;
	return backgroundObject;
}

//---------------------------------------------------------------------------------------------------------------------
- (BackgroundObject*)createWithRepeatOffset:(int)offset
{
	BackgroundObject *backgroundObject = [self copy];
	backgroundObject->posy += offset;
	backgroundObject.sprite.position = CGPointMake(self.posx, self.posy + offset);
	return backgroundObject;
}

@end
